package ysq.xyg.recovery.controller;

import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.util.BaseConstant;

import cn.hutool.core.util.StrUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
import ysq.xyg.base.aspect.BaseLog;
import ysq.xyg.base.controller.BaseController;
import ysq.xyg.base.util.BaseConstant;
import ysq.xyg.base.model.dto.ReturnEntity;
import ysq.xyg.recovery.model.po.RecoveryOrder;
import ysq.xyg.recovery.model.vo.RecoveryOrderVo;
import ysq.xyg.recovery.service.RecoveryOrderService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 回收金模块-订单管理controller层
 *
 * @author congcong tao
 * @date 2019-7-11 20:30:57
 */
@RestController
public class RecoveryOrderController extends BaseController {

    private static Logger log= LoggerFactory.getLogger(RecoveryOrderController.class);
    @Resource
    private RecoveryOrderService recoveryOrderService;

    private RecoveryOrder recoveryOrder;

    /**
     * 分页查询
     *
     * @param recoveryOrderVo 对象
     * @param pageSize 展示数量
     * @param pageNum 当前页面
     * @author congcong tao
     * @date 2019-7-11 20:30:57
     */
    @BaseLog(module = "回收金模块",className = "订单管理",methods = "分页查询",businessType = BaseConstant.SYS_BUSINESS_TYPE_GET,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryOrder/page",method = RequestMethod.POST)
    public ReturnEntity page(RecoveryOrderVo recoveryOrderVo, int pageSize, int pageNum){
        ReturnEntity returnEntity = recoveryOrderService.page(recoveryOrderVo,pageSize,pageNum);
        return returnEntity;
    }

    /**
     * 跳转连接
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-11 20:30:57
     */
    @RequestMapping(value = "/recoveryOrder/getEntity",method = RequestMethod.GET)
    public ModelAndView getEntity(String id){
        ModelAndView view = new ModelAndView("/recovery/recoveryOrderUpdateOrSave");
        if(StrUtil.isNotEmpty(id)){
            recoveryOrder = recoveryOrderService.selectByPrimaryKey(id);
            view.addObject("recoveryOrder", recoveryOrder);
        }
        return view;
    }
    /**
     * 删除
     *
     * @param id 主键id
     * @author congcong tao
     * @date 2019-7-11 20:30:57
     */
    @BaseLog(module = "回收金模块",className = "订单管理",methods = "删除",businessType = BaseConstant.SYS_BUSINESS_TYPE_DELETE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryOrder/delete")
    public ReturnEntity delete(HttpServletRequest request,String id){
        return recoveryOrderService.delete(id,acceptCurrentUser(request));
    }

    /**
     * 处理订单
     * @param status
     * @param id
     * @param status
     * @author congcong tao
     * @date 2019-07-12 21:31
     */
    @RequestMapping(value = "/recoveryOrder/updateStatus")
    public ReturnEntity updateStatus(String id, String status){
        RecoveryOrder recoveryOrder = new RecoveryOrder();
        recoveryOrder.setId(id);
        recoveryOrder.setStatus(status);
        // recoveryOrderService.saveOrder("oc7Fe1Nct92Z0qoAhCs9R6b_bPpw", "1213", 1000 * 12, 2);
        int info = recoveryOrderService.updateByPrimaryKeySelective(recoveryOrder);
        if (info <= 0) {
            return new ReturnEntity(BaseConstant.FAIL,BaseConstant.DO_FAIL);
        }
        return new ReturnEntity();
    }

    /**
     * 添加或修改
     *
     * @param recoveryOrderVo Vo对象
     * @author congcong tao
     * @date 2019-7-11 20:30:57
     */
    @BaseLog(module = "回收金模块",className = "订单管理",methods = "添加或修改",businessType = BaseConstant.SYS_BUSINESS_TYPE_UPDATE,operatorType= BaseConstant.SYS_OPERATOR_TYPE_PC)
    @RequestMapping(value = "/recoveryOrder/addOrUpdate",method = RequestMethod.POST)
    public ReturnEntity delete(HttpServletRequest request,RecoveryOrderVo recoveryOrderVo){
        return recoveryOrderService.addOrUpdate(recoveryOrderVo,acceptCurrentUser(request));
    }
}